from ability.models import Student
from rest_framework import permissions

class CustomIsAuthenticated(permissions.IsAuthenticated):
    def has_permission(self, request, view):
        print("IsAuthenticated", request.user)
        return super().has_permission(request, view)

class AdminPermission(permissions.BasePermission):

    def has_permission(self, request, view):
        user = request.user
        if user.user_status != 'N':
            return False
        return True if user.user_type == 'A' else False

class TeacherPermission(permissions.BasePermission):

    def has_permission(self, request, view):
        user = request.user
        if user.user_status != 'N':
            return False
        return True if user.user_type == 'T' else False

class StudentPermission(permissions.BasePermission):

    def has_permission(self, request, view):
        user = request.user
        if user.user_status != 'N':
            return False
        student = Student.objects.filter(user=user).first()
        if student is None:
            return False
        if student.belong_class and student.belong_class.status != 'N':
            return False
        return True if user.user_type == 'S' else False

class ExpertPermission(permissions.BasePermission):

    def has_permission(self, request, view):
        if user.user_status != 'N':
            return False
        return request.user.user_type == 'E'


class AllowAny(permissions.AllowAny):

    def has_permission(self, request, view):
        print("AllowAny", request)
        return True
